package com.repository;

import com.dto.PackageDto;
import com.dto.VersionDto;
import com.entity.SysVersionManage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Yadasu
 * @date 2021/1/12 14:18
 */
public interface SysVersionRepository extends JpaRepository<SysVersionManage, Integer> {


    @Query(value = "select * from sys_installation_package_manage  where status =1 order by update_time desc  ", nativeQuery = true)
    List<SysVersionManage> findTheNewestVersionIds();

    @Query(value = "SELECT * FROM `sys_installation_package_manage` where installation_package_name=?1 and installation_package_version=?2", nativeQuery = true)
    SysVersionManage findByPackageNameAndPackageVersion(String name, String version);


    @Query(value = "SELECT * FROM `sys_installation_package_manage` where installation_package_name=?1 and current_version=?2", nativeQuery = true)
    SysVersionManage  getByPackageNameAndPackageVersion(String name, String version);

    @Query(value = "SELECT * FROM `sys_installation_package_manage` where installation_package_name=?1 ", nativeQuery = true)
    SysVersionManage findByPackageName(String name);


    @Modifying
    @Transactional
    @Query(value ="UPDATE sys_installation_package_manage set installation_package_version=?1,update_by=?3 where deploy_id=?2" ,nativeQuery = true)
    Integer getByAppName(String version,Integer id,String username);


    @Modifying
    @Transactional
    @Query(value ="UPDATE sys_installation_package_manage  set update_time=NOW(),current_version=?1,remote_development=1,update_by=?3 where deploy_id=?2" ,nativeQuery = true)
    Integer getByAppId(String version,Integer id,String username);


}
